package com.study.system.log.service.Impl;

import com.study.system.log.domain.Log;
import com.study.system.log.domain.UserLog;
import com.study.system.log.mapper.LogMapper;
import com.study.system.log.service.LoginService;
import com.study.system.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author 669
 * @CreateDate 2022/4/20 10:45
 * @Version 1.0
 */
public class LoginServiceImpl implements LoginService {
    @Override
    public int addLog(Log log) {
        SqlSession session = MybatisUtils.getSqlSession();
        LogMapper mapper = session.getMapper(LogMapper.class);
        int i = mapper.addLog(log);
        session.commit();
        return i;
    }

    @Override
    public int delById(int id) {
        SqlSession session = MybatisUtils.getSqlSession();
        LogMapper mapper = session.getMapper(LogMapper.class);
        int i = mapper.delById(id);
        session.commit();
        return i;
    }

    @Override
    public int delByUserId(int eid) {
        SqlSession session = MybatisUtils.getSqlSession();
        LogMapper mapper = session.getMapper(LogMapper.class);
        int i = mapper.delById(eid);
        session.commit();
        return i;
    }

    @Override
    public int delByUsername(String name) {
        return 0;
    }

    @Override
    public List<UserLog> selectAllLog() {
        SqlSession session = MybatisUtils.getSqlSession();
        LogMapper mapper = session.getMapper(LogMapper.class);
        List<UserLog> userLogs = mapper.selectAllLog();
        return userLogs;
    }

    @Override
    public List<UserLog> selectBynameLog(String name) {
        SqlSession session = MybatisUtils.getSqlSession();
        LogMapper mapper = session.getMapper(LogMapper.class);
        List<UserLog> userLogs = mapper.selectBynameLog(name);
        return userLogs;
    }
}
